<?php

class GcalEvent
{
	public function __construct($cal, $event) 
	{
  		$this->cal = $cal;
		$this->event = $event;
	}	
	
	function get()
	{
		$eventURL = 'http://www.google.com/calendar/feeds/' .
		            $this->cal . 
					'/public/full/' .
					$this->event;
					
		$event = file_get_contents($eventURL);
		$this->eventXML = new SimpleXmlElement($event);
		$this->gd = $this->eventXML->children('http://schemas.google.com/g/2005');
		
		if (strlen ((string) $this->eventXML->content) > 0)
		{
			$this->details = new SimpleXmlElement ((string) $this->eventXML->content);
		}
		
		return true;
	}
	
	function title()
	{
		return (string) $this->eventXML->title;
	}

	function content()
	{
		return (string) $this->eventXML->content;
	}

	function where()
	{
		return $this->gd->where->attributes()->valueString;
	}

	function date()
	{
		return $this->startTime();
	}
	
	function startTime()
	{
		return new DateTime ($this->gd->when->attributes()->startTime);
	}

	function endTime()
	{
		return new DateTime ($this->gd->when->attributes()->endTime);
	}
	
	function postcode()
	{
		return $this->details->postcode;
	}
	
	function address()
	{
		return $this->details->address;
	}
	
	function description()
	{
		return $this->details->description;
	}
	
}
?>